﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Springboard : MonoBehaviour {

    public float pushForce = 0f;
    public float pushHeigh = 20f;

    private void OnTriggerEnter2D(Collider2D collision) {
        var rg2d = collision.GetComponentInParent<Rigidbody2D>();
        if (rg2d.velocity.y >= 0)
            return;
        var pushDir = rg2d.transform.position - transform.position;
        rg2d.velocity = Vector2.zero;
        rg2d.AddForce(pushDir.normalized * pushForce, ForceMode2D.Force);
        rg2d.AddForce(Vector2.up * pushHeigh, ForceMode2D.Force);
    }

}
